<template>
  <div class="photoinfo-container">
    <h3 class="title">{{ photoinfo.title }}</h3>
    <p class="info">
      <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
      <span>点击{{ photoinfo.click }}次</span>
    </p>
    <hr />

    <div class="thumb-img-list">
      <vue-preview :slides="photolist"></vue-preview>
      <!-- <img
        class="preview-img"
        :src="item.src"
        v-for="(item, index) in photolist"
        :key="index"
        height="100"
        @click="$preview.open(index, photolist)"
      /> -->
    </div>

    <div class="content" v-html="photoinfo.content"></div>
    <!-- 评论子组件必须传递参数newsid -->
    <comment :newsid="id"></comment>
  </div>
</template>

<script>
import comment from "../sub-components/Comment.vue";

export default {
  data() {
    return {
      photoinfo: {},
      photolist: [],
    };
  },
  props: ["id"],
  methods: {
    async getPhotoInfo() {
      const { data } = await this.$http.get("/api/getimageInfo/" + this.id);
      if (data.status == 0) {
        this.photoinfo = data.message[0];
      }
    },
    async getThumblmg() {
      const { data } = await this.$http.get("/api/getthumimages/" + this.id);
      if (data.status == 0) {
        data.message.forEach((item) => {
          item.w = 600;
          item.h = 400;
          item.msrc = item.src;
        });
        this.photolist = data.message;
      }
    },
  },
  created() {
    this.getPhotoInfo();
    this.getThumblmg();
  },
  components: { comment },
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
}
.titie {
  font-size: 15px;
  text-align: center;
  margin: 15px 0;
}
.info {
  font-size: 12px;
  display: flex;
  justify-content: space-between;
}
.content {
  font-size: 13px;
  line-height: 30px;
}
.thumb-img-list {
  /deep/ .my-gallery {
    //deep深层作用选择器
    display: flex;
    flex-wrap: wrap; //默认换行
    figure {
      width: 30%;
      margin: 5px;
      img {
        width: 100%;
        box-shadow: 0 0 8px #999;
        border-radius: 5px;
      }
    }
  }
}
</style>